/**
 * @author Hanxing
 * @date 2018年2月28日 下午2:35:23
 * @Description 
 */
package com.cxrj.zhsq.userManage.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.cxrj.zhsq.annotation.SystemControllerLog;
import com.cxrj.zhsq.userManage.entity.AppUser;
import com.cxrj.zhsq.userManage.service.AppUserService;

/**
 * @author : hanxing
 * @date 创建时间：2018年2月28日 下午2:35:23
 * @description
 * @return
 */
@RestController
public class AppUserController {
	@Resource
	private AppUserService appUserService;

	/**
	 * 分页查询APP用户信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectAppUser", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> selectAppUser(HttpServletRequest request, HttpServletResponse response) {
		return appUserService.selectAppUser(request, response);
	}

	@RequestMapping(value = "selectAppUserById", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> selectAppUserById(String userId) {
		return appUserService.selectAppUserById(userId);
	}

//	@RequestMapping(value = "deleteAppUserById", method = RequestMethod.POST)
//	@SystemControllerLog(description = "删除App用户")
//	public Map<String, Object> deleteAppUserById(@RequestParam Map<String, Object> map) {
//		try {
//			appUserService.deleteAppUserById(map);
//			map.put("result", 0);
//		} catch (Exception e) {
//			map.put("result", -1);
//			throw new RuntimeException(e);
//		}
//		return map;
//	}

	@RequestMapping(value = "deleteAppUserByIds", method = RequestMethod.POST)
	@SystemControllerLog(description = "冻结App用户")
	public Map<String, Object> deleteAppUserByIds(String id) {
		Map<String, Object> resultMap = new HashMap<>();
		try {
			resultMap =	appUserService.updateAppUserByIds(id);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}
	
	@RequestMapping(value = "thawAppUserByIds", method = RequestMethod.POST)
	@SystemControllerLog(description = "解冻App用户")
	public Map<String, Object> thawAppUserByIds(String id) {
		Map<String, Object> resultMap = new HashMap<>();
		try {
			resultMap =	appUserService.updateAppUserByThaw(id);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}
	/**
	 * 查询所有App用户
	 * @return
	 */
	@RequestMapping("selectAllAppUser")
	public Map<String, Object> selectAllAppUser(){
		return appUserService.selectAllAppUser();
	}
	
	/**
	 * 修改app用户
	 * 
	 * @return
	 */
	@RequestMapping(value = "appUserUpdate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> appUserUpdate(AppUser appUser, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = appUserService.updateUser(appUser);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}
}
